<template>
    <a-form-model ref="form" :model="mdl" :rules="rules">
        <a-row :span="24">
            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="$ti18('rxForm.name','名称')" prop="name">
                    <a-input
                        :placeholder="$ti18('rxForm.name','名称')"
                        style="display: inline-block;vertical-align: middle;"
                        v-model="mdl.name"

                    />
                </a-form-model-item>
            </a-col>
            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="i18n('form.enterpriseID','企业ID')" prop="corpId">
                    <a-input
                        :placeholder="i18n('form.enterpriseID','企业ID','input')"
                        class="defaultWith"
                        v-model="mdl.corpId"

                    />
                </a-form-model-item>
            </a-col>

        </a-row>
        <a-row :span="24">
            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="i18n('form.appID','应用ID')" prop="agentId">
                    <a-input
                        :placeholder="i18n('form.appID','应用ID')"
                        class="defaultWith"
                        v-model="mdl.agentId"

                    />
                </a-form-model-item>
            </a-col>

            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="i18n('form.secretKey','应用密钥')" prop="secret">
                    <a-input
                        :placeholder="i18n('form.secretKey','应用密钥')"

                        v-model="mdl.secret"

                    />
                </a-form-model-item>
            </a-col>
        </a-row>
        <a-row :span="24">
            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="i18n('form.appHomeAddress','应用主页地址')" >
                    <a-input
                        :placeholder="i18n('form.appHomeAddress','应用主页地址')"
                        class="defaultWith"
                        v-model="mdl.homeUrl"
                        :rows="4"
                    />
                </a-form-model-item>
            </a-col>
            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="i18n('form.trustDomainName','信任域名')">
                    <a-input
                        :placeholder="i18n('form.trustDomainName','信任域名')"
                        class="defaultWith"
                        v-model="mdl.domain"

                    />
                </a-form-model-item>
            </a-col>

        </a-row>
        <a-row :span="24">
            <a-col :span="12">
                <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" :label="i18n('form.remarks','备注')">
                    <a-input
                        :placeholder="i18n('form.remarks','备注')"
                        class="defaultWith"
                        :rows="4"
                        v-model="mdl.description"
                    />
                </a-form-model-item>
            </a-col>

        </a-row>


    </a-form-model>
</template>

<script>
    import {BaseFormModel, RxDialog, Dialog} from "@lowcode/jpaas-common-lib";
    import PlatFormApi from '@/api/user/org/platForms';

    export default {
        name: "PlatformsWeChat",
        mixins: [BaseFormModel],
        components: {
            RxDialog
        },
        props: ["dataJson"],
        data() {
            return {
                rules: {
                    name: [
                        {required: true, message: this.i18n('form.appName','请输入应用名称','input'), trigger: 'blur'},
                    ],
                    corpId: [
                        {required: true, message: this.i18n('form.enterpriseID','请输入企业ID','input'), trigger: 'blur'},
                    ],
                    agentId: [
                        {required: true, message: this.i18n('form.appID','请输入应用ID','input'), trigger: 'blur'},
                    ],
                    secret: [
                        {required: true, message: this.i18n('form.secretKey','请输入密钥','input'), trigger: 'blur'},
                    ]
                }
            }
        },
        created() {
            if (!this.dataJson || !this.dataJson.corpId) {
                return;
            }
            this.mdl = this.dataJson;
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "platForms", key);
            },
            checkAndSave(callback) {
                var self_ = this;
                this.$refs.form.validate(valid => {
                    if (!valid) {
                        return;
                    }
                    self_.checkCanSave(callback);
                });
            },
            async checkCanSave(callback) {
                var self_ = this;
                this.mdl.type="2";
                var res = await PlatFormApi.checkCanSave(this.mdl);
                if (!res.success) {
                    return;
                }
                callback(this.mdl);
            },
        }
    }
</script>

<style scoped>

</style>